package com.sk.bilibili.model.activity;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.mapper.SearchMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.activity.SearchActivity;

public class SearchModel extends BaseModel<SearchActivity> {

    @Autowired
    SearchMapper searchMapper;
    private int size = 8;

    @Override
    public void loadData() {
        RequestUtils.process(searchMapper.getRandom(size),
                searches -> view.loadTipSuccess(searches));
        RequestUtils.process(searchMapper.getHistory(),
                searches -> view.loadHistorySuccess(searches));
    }

    public void clearHistory() {
        RequestUtils.process(searchMapper.deleteAll(),
                unused -> view.clearHistorySuccess());
    }

    public void addSearchHistory(String keyword) {
        RequestUtils.process(searchMapper.addSearchHistory(keyword));
    }

}